package com.buka.order.Listener;


import com.buka.order.config.RabbitMqConfig;
import com.buka.order.service.OrderService;
import com.buka.order.service.TaskService;
import com.buka.pojo.Order;
import com.buka.pojo.Task;
import org.springframework.amqp.rabbit.annotation.RabbitListener;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;

@Component
public class OrderListener {
    @Autowired
    TaskService taskService;
    @Autowired
    OrderService orderService;

    // 回滚(给mq发消息 订单服务关闭订单（改状态）)
    @RabbitListener(queues = RabbitMqConfig.ORDER_QUEUE)
    public void order(Order order){
        order.setStatus(7);
    orderService.update(order);
    }


    //删除消息表中的数据（给mq发消息删除消息数据）
    @RabbitListener(queues = RabbitMqConfig.TASK_QUEUE)
    public void task(Task task){
        taskService.delete(task.getId());
    }

    @RabbitListener(queues = RabbitMqConfig.NOTIFY_QUEUE)
    public void notify(Order order){
        orderService.update(order);
    }
}
